package part1basiclock;

// 验证可重入锁 -> Synchronized
public class TestLock06 {

    public static void main(String[] args) {
        Phone01 phone = new Phone01();

        // T1 线程在外层获取锁时，也会自动获取里面的锁
        new Thread(() -> {
            phone.sendSMS();
        }, "T1").start();

        new Thread(() -> {
            phone.sendSMS();
        }, "T2").start();
    }

}


class Phone01 {
    public synchronized void sendSMS() {
        System.out.println(Thread.currentThread().getName() + " sendSMS");
        sendEmail();
    }

    public synchronized void sendEmail() {
        System.out.println(Thread.currentThread().getName() + " sendEmail");
    }
}